/*
 * @lc app=leetcode.cn id=917 lang=cpp
 *
 * [917] 仅仅反转字母
 */

// @lc code=start
class Solution
{
public:
  string reverseOnlyLetters(string s)
  {
    int L = 0, R = s.size() - 1;
    while (L < R) {
      while (L < R && !isalpha(s[L]))
        ++L;
      while (L < R && !isalpha(s[R]))
        --R;
      char tmp = s[L];
      s[L++] = s[R];
      s[R--] = tmp;
    }
    return s;
  }
};
// @lc code=end
